package models

//	"github.com/gin-gonic/gin"

type Majordictionary struct {
	Mno   string `gorm:"column:mno"`
	Cname string `gorm:"column:cname"`
	Iplan string `gorm:"column:iplan"`
	Oplan string `gorm:"column:oplan"`
}

func GetAllMajordictionary(majorParam map[string]interface{}) (error, []Majordictionary, int64) {
	var majordata []Majordictionary
	page := majorParam["page"].(int)
	pageSize := majorParam["limit"].(int)
	searchText := majorParam["searchText"].(string)
	var total int64
	err := db.Table("majordictionary").Where("mno like ?", "%"+searchText+"%").Order("mno ASC").Count(&total).Find(&majordata).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, majordata, total
}

func AddMajordictionary(majordata Majordictionary) (error, Majordictionary) {
	err := db.Table("majordictionary").Select("mno", "cname", "iplan", "oplan").Create(&majordata).Error
	return err, majordata
}

func UpdateMajordictionary(mno string,majordata Majordictionary) (error,Majordictionary){
	err := db.Table("majordictionary").Where("mno = ?",majordata.Mno).Updates(&majordata).Error
	return err,majordata
}

func DeleteMajordictionary(mno string)(error,Majordictionary){
	var majordata Majordictionary
	majordata.Mno = mno
	err := db.Table("majordictionary").Where("mno = ?",mno).Find(&majordata).Delete(Majordictionary{}).Error
	return err,majordata
}
